package com.ruoyi.web.cp.service;

import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class NumberChecker {

    public static int[] parseIntArr(String[] input) {
        int[] numbers = new int[10];
            for (int i = 0; i < 10; i++) {
                numbers[i] = Integer.parseInt(input[i]);
            }

        return numbers;
    }

    /**
     * 检查指定范围内的数组是否递增
     *
     * @param array 数组
     * @param start 起始索引
     * @param length 检查长度
     * @return 如果范围内递增则返回true；否则返回false
     */
    public static boolean isIncreasing(String[] strs, int start, int length) {
        int[] array = parseIntArr(strs);
        for (int i = start; i < start + length - 1; i++) {
            if (array[i] >= array[i + 1]) {
                return false;
            }
        }
        return true;
    }

    /**
     * 检查指定范围内的数组是否递减
     *
     * @param array 数组
     * @param start 起始索引
     * @param length 检查长度
     * @return 如果范围内递减则返回true；否则返回false
     */
    public static boolean isDecreasing(String[] strs, int start, int length) {
        int[] array = parseIntArr(strs);
        for (int i = start; i < start + length - 1; i++) {
            if (array[i] <= array[i + 1]) {
                return false;
            }
        }
        return true;
    }

    //前4期是否跳号
    public static boolean isSkipNumbers(List<String []> codes) {
        for (int i = 0; i < codes.get(0).length; i++) {
            String code3 = codes.get(3)[i];
            String code2 = codes.get(2)[i];
            String code1 = codes.get(1)[i];
            String code0 = codes.get(0)[i];
            if (code3.equals(code1) && code1.equals(code0) && !code2.equals(code0)) {
                return true;
            }
        }
        return false;
    }


    public static final Integer SKIP_NUMBER2 = 9;
    //前4期是否跳号
    public static boolean isSkipNumbers2(List<String []> codes) {
        for (int i = 0; i < codes.get(0).length; i++) {
            Set<String> set = new HashSet<>();
            for (int j = 0; j < codes.size(); j+=2) {
                set.add(codes.get(j)[i]);
            }
            if (set.size() == 1) {
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        String str = FileUtil.readString("D:\\乱七八糟\\0701.txt", "utf8");
        JSONObject jsonObject = JSONObject.parseObject(str);
        JSONArray datas = jsonObject.getJSONArray("data");
        List<String[]> lists = new ArrayList<>();
        for (int i = 0; i < 9; i++) {
            JSONObject data = datas.getJSONObject(i);

            lists.add(data.getString("code").split(","));
        }
        System.out.println(isSkipNumbers2(lists));
    }
}
